<?php

namespace App\Models;

use App\ShopStatusType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Notifications\Notifiable;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Core implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Notifiable,Authenticatable, Authorizable, CanResetPassword;
    const TABLE = 'users';
    protected $table = self::TABLE;

    protected $fillable = [
        'id','shop','username', 'email', 'password','last_visited_ip'
    ];

    protected $appends = [

    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token','shop',
    ];

    public function member()
    {
        return $this->hasOne('App\Models\Member', 'user_id');
    }

    public function shop()
    {
        return $this->hasOne('App\Models\Shop');
    }

    //验证是否是商家
    public function getIsMerchantAttribute(){
        $user_id = $this->id;
        $shop = Shop::where('user_id',$user_id)->ShopAvailable()->first();
        if(!$shop){
            return false;
        }
        return $shop;
    }

    //验证是否是管理员
    public function getIsManagerAttribute()
    {
        return true;
    }

}
